package unit

import (
	"lnzw/common/math"
	"lnzw/engine/aoi/crosslinks"
	"lnzw/server/test/test_fyne/test_3/data"
	"time"
)

type MonsterUnit struct {
	data.BaseUnit
}

func (m *MonsterUnit) GetUnitType() data.UnitType {
	return data.Monster
}

func (m *MonsterUnit) OnEnterMap(datamap *data.Map) {
	m.BaseUnit.OnEnterMap(datamap)
	go func() {
		for {
			p := m.GetPosition()
			var x_off int
			if math.RandBool() {
				x_off = datamap.GetCellSize()
			} else {
				x_off = -datamap.GetCellSize()
			}
			var y_off int
			if math.RandBool() {
				y_off = datamap.GetCellSize()
			} else {
				y_off = -datamap.GetCellSize()
			}
			m.NowMap.MoveEntity(m, crosslinks.Point{X: p.X + float32(x_off), Y: p.Y + float32(y_off)})
			time.Sleep(time.Millisecond * 1000)
		}
	}()
}

func NewMonsterUnit(id int64, x int, y int) *MonsterUnit {
	return &MonsterUnit{
		BaseUnit: data.BaseUnit{Id: id, AOIEntity: crosslinks.AOIEntity{Pos: crosslinks.Point{X: float32(x), Y: float32(y)}}},
	}
}
